// Last Update:2015-01-27 23:08:59
/**
 * @file gateway_mac.c
 * @brief 
 * @author 
 * @version 0.1.00
 * @date 2015-01-27
 */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>

#include <net/if_arp.h>

#include "unpifi.h"

int main(int argc, char *argv[])
{
	int sockfd;
	struct ifi_info *ifi;
	struct arpreq arpreq;
	struct sockaddr_in *sin;
	unsigned char *ptr = NULL;

	sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
	for (ifi = get_ifi_info(AF_INET, 0); ifi != NULL; ifi = ifi->ifi_next)
	{
		printf("%s\n", Sock_ntop(ifi->ifi_addr, sizeof(struct sockaddr_in)));
	}
	sin = (struct sockaddr_in *)&arpreq.arp_pa;
	memcpy(sin, ifi->ifi_addr, sizeof(struct sockaddr_in));
	if (ioctl(sockfd, SIOCGARP, &arpreq) < 0)
	{
		perror("ioctl error");
		exit(EXIT_FAILURE);
	}
	ptr = &arpreq.arp_ha.sa_data[0];
	printf("%x %x %x %x %x %x\n", 
			*ptr, *(ptr + 1), *(ptr + 2),
			*(ptr + 3), *(ptr + 4), *(ptr + 5));

	return 0;
}
